﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProjetoComperio.DataLayer.Infra;
using ProjetoComperio.DataLayer.Entities;

namespace ProjetoComperio.BusinessLogicLayer
{
    public class SearchBLL : ComperioDataObject
    {

        /// <summary>
        /// This method returns the cotributions that contains the
        /// specified searchText in their title or description
        /// </summary>
        /// <param name="seachText"></param>
        /// <returns></returns>
        public IQueryable<Contribution> SearchContribution(String seachText, String contributionType)
        {
            IQueryable<Contribution> searchResult = null;

            switch (contributionType)
            {
                case "Project":
                    searchResult = DbContext.Contributions.OfType<Project>().Where(project => project.Title.Contains(seachText) || project.Description.Contains(seachText));
                    break;

                case "Event":
                    searchResult = DbContext.Contributions.OfType<Event>().Where(eventEntity => eventEntity.Title.Contains(seachText) || eventEntity.Description.Contains(seachText));
                    break; 

                case "Publication":
                    searchResult = DbContext.Contributions.OfType<Publication>().Where(eventEntity => eventEntity.Title.Contains(seachText) || eventEntity.Description.Contains(seachText));
                    break; 
            }

            return searchResult;
        }
    }
}
